<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-input-block{
        margin-left: 90px;
    }
</style>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">CPS联盟统计</a>
            <a><cite>推广链接</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">链接ID：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id" placeholder="请输入链接ID" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">小程序：</label>
                    <div id="pMenu1" style="width:100%;flex:1"></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">分销商：</label>
                    <div id="pMenu"></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">时间：</label>
                    <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                        <div class="layui-input-inline" style="margin-right:10px">
                            <input type="text" autocomplete="off" name="start_date" id="start_date" class="layui-input"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" name="end_date" id="end_date" class="layui-input"
                                   placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="linkList" lay-filter="linkList"></table>
    </div>
    
    <script>
        let params = {
            elem: '#linkList'
            , url: '/admin/alliance/linkList' //数据接口
            , id: 'linkList'
            , limit:15
            , page:true
            , cols: [[ //表头
                { field: 'id', title: '链接ID', width: 90, sort: true, align:'center' }
                , { field: 'applet_name', title: '投放小程序', width:126, align:'center' }
                , { field: 'advertiser_id', title: '广告账户ID',width:166, align:'center' }
                
                , { title: '投放开关', templet: function (d) {
                        return d.link_switch == 1 ? '开启' : '关闭'
                    }, align:'center', width: 90
                }
                , { field: 'video_name', title: '短剧名称', align:'center', width: 160 }
                , { title: '投放平台', templet: function (d) {
                        let type = ''
                        switch (d.media_id) {
                            case 1:
                                type = '抖音'
                                break;
                            case 2:
                                type = '快手'
                                break;
                            case 3:
                                type = '百度'
                                break;
                            case 4:
                                type = '内推'
                                break;
                        }
                        return type
                    }, align:'center', width:90
                }
                , { field: 'responsibility_person', title:'负责人', align:'center'}
                , { title: '回传开关', templet: function (d) {
                        return d.is_open == 1 ? '开启' : '关闭'
                    }, align:'center', width: 90
                }
                , { field: 'echo_rate', title: '回传率', align:'center', width: 80 }
                // , { field: 'echo_rule_config_id', title: '回传规则配置ID', align:'center' }
                , { field: 'recharge_template_id', title: '充值模板ID', align:'center', width:100 }

                , { field: 'today_cost', title:'今日花费', align:'center', width: 108}
                , { field: 'spend', title:'历史花费', align:'center', width: 105}
                , { field: 'percapita_recharge', title:'人均贡献', align:'center', width: 105}
                , { field: 'day_recharge', title:'今日激活充值', align:'center', width: 115}
                , { field: 'recharge_price', title:'累计充值', align:'center', width: 105}
                //, { field: 'recharge_price', title:'充值金额', align:'center', width: 105}
                , { field: 'revenue' , title:'盈收', align:'center', width: 80}
                , { field: 'created_at', title: '链接创建时间', templet: function (d) {
                        return dayjsFormat(d.created_at)
                    }, align:'center', width:176
                }
            ]]
        }
        

        let selectParams = {
            url: '/admin/distribution/selectList',
            elem: '#pMenu',
            selected: [],
            tips: '选择分销商',
            name: 'distributor_id',
            field_id: 'id',
            field_Name: 'name',
        }
        selectN(selectParams)

        let selectParams1 = {
            url: '/admin/applet/select',
            elem: '#pMenu1',
            selected: [],
            tips: '选择小程序',
            name: 'official_account_id',
            field_id: 'id',
            field_Name: 'name',
        }
        selectN(selectParams1)


        tableList(params)
        layui.use(['table','laydate'], function () {
            var table = layui.table;
            var laydate = layui.laydate;
            table.on('edit(linkList)', function(obj){
                var field = obj.field //得到字段
                ,value = obj.value //得到修改后的值
                ,data = obj.data; //得到所在行所有键值
                var update = {};
                if(!isNaN(Number(value))){
                    var update = {};
                    update[field] = value;
                    update['earn'] = value - data.spend
                    obj.update(update);
                    Ajax('/admin/alliance/editSpend', { id:data.id,spend:value }).then(result => {
                        table.reloadData('linkList')
                    });
                }else{
                    table.reloadData('linkList')
                    layer.msg('请输入数字', {
                        icon: 5
                    })
                }
            });
            
            //日期范围
            laydate.render({
                elem: '#time'
                , range: ['#start_date', '#end_date']
                ,format: 'yyyy-MM-dd'
            });
        });
    </script>
</body>

</html>